<template>
	<view>
		<view class="page-body">
			<!-- <navbar :custom-back="return_indexs" background="#fff" title="直播回4放"></navbar> -->
			<u-navbar back-text="返回" :custom-back="return_indexs" title="直播回放"></u-navbar>
			<view v-if="isLive" class="p20 bg-white u-border-top">
				<u-section title="正在直播" sub-title="前往直播间" @click="app.goPage('/pagesA/live/player')" subColor="#5CB61A" :showLine="false"></u-section>
			</view>
			<scroll-view>
				<!-- <view v-if="loading"></view> -->
				<view>
					<!-- 如果登录了，就展示房间列表 -->
					<roomlists :room="room.list"></roomlists>
				</view>
				<uni-load-more :status="loadingType"></uni-load-more>
			</scroll-view>
		</view>
	</view>
	
</template>

<script>
	import roomlists from './components/roomLists.vue';
	import navbar from '@/components/navbar.vue'

	const app = getApp()
	export default {
		components: {
			roomlists,
			navbar
		},
		data() {
			return {
				isLive: false,
				room: {
					list: []
				},
				loading: true,
				param: { //传递参数
					page: 0, //默认页
				},
				loadingType: 'more', //加载更多状态
			}
		},
		mixins: [],
		computed: {},
		methods: {
			return_indexs() {
				console.log(234234)
				uni.navigateTo({
					url: '/pages/member/center/index'
				});
			},
			loginSuccess() {
				this.isLogin = true
				this.auth()
			},
			getRoomList(source = 'add') {
				
				//没有更多直接返回
				if (source == 'add' && this.loadingType == 'nomore') {
					return;
				}
				if (source === 'refresh') {
					this.param.page = 0;
					this.room.list = [];
				}
				
				this.param.page++;
				this.$u.get('live/api.live/getList', this.param).then(res => {
					this.isLive = res.data.isLive;
					this.room.list = this.room.list.concat(res.data.list);
					//loaded新字段用于表示数据加载完毕，如果为空可以显示空白页
					this.$set(this.room, 'loaded', true);
					//判断是否还有下一页，有是more  没有是nomore
					this.loadingType = this.param.page == res.data.page_count ? 'nomore' : 'more';
							
				})
				
			},
		},
		events: {},
		async created() {
			this.app.isLogin(this); //强制登陆
			this.getRoomList()
		}
	}
</script>

<style lang="scss" scoped>

</style>
